<template>
  <div class="category">
    <h1>当前求和为：{{sum }}</h1>
    <h1>当前求和*10为：{{ bigSum }}</h1>
    <h3>我在{{ school }}学习{{ subject }}</h3>
    <select v-model.number="n">
      <option value="1">1</option>
      <option value="2">2</option>
      <option value="3">3</option>
    </select>
    <h3>总人数是：{{PersonList.length}}</h3>
    <button @click="JIA(n)">+</button>
    <button @click="JIAN(n)">-</button>
    <button @click="jiaOdd(n)">当前求和为奇数再加</button>
    <button @click="jiaWait(n)">等一等再见</button>

  </div>
</template>

<script>
import {mapState, mapGetters, mapMutations, mapActions} from "vuex";

export default {
  name: "Count",
  data() {
    return {
      n: 1 //用户选择的数字
    }
  },
  methods: {
    // 借助 mapMutations 生成对应的方法，方法中会调用commit去联系mutations
    ...mapMutations("countOptios",['JIA', 'JIAN']),

    // 借助 mapActions 生成对应的方法，方法中会调用 dispatch 去联系 actions
    ...mapActions("countOptios",['jiaOdd', 'jiaWait'])

  },
  mounted() {
    // console.log(this.$store)
  },
  computed: {
    //借助mapState生成计算属性,从state中读取数据(对象写法)
    // ...mapState({he: 'sum', xx: "school", dz: 'subject'}),

    //借助mapState生成计算属性，从state中读取数据。（数组写法)
    ...mapState("countOptios",['sum', 'school',"subject"]),
    //借助mapState生成计算属性，从getters中读取数据。（数组写法)
    ...mapGetters("countOptios",['bigSum']),


    ...mapState("peronOptinos",['PersonList']),
  }
}
</script>

<style scoped>
button {
  margin-left: 5px;
}
</style>